package com.kk.product.listener;

import com.kk.product.service.ProductService;
import com.kk.to.OrderToProduct;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * projectName: b2c-store
 *
 * @author: kjy
 * time: 2023/5/10 16:47
 * description: 商品的mq消息监听
 */
@Component
public class ProductRabbitMQListener {

    @Autowired
    private ProductService productService;

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "sub.queue"),
            exchange = @Exchange("topic.ex"),
            key = "sub.number"

    ))
    public void subNumber(List<OrderToProduct> orderToProducts){
        productService.subNumber(orderToProducts);
    }
}
